//
//  DingyueDetailsCell.m
//  网易新闻
//
//  Created by dllo on 15/10/8.
//  Copyright (c) 2015年 Lx. All rights reserved.
//

#import "DingyueDetailsCell.h"
#import "Settings.h"
@interface DingyueDetailsCell()
@property(nonatomic, retain)UILabel *ptime;
@end
@implementation DingyueDetailsCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [[Settings shareSettings]color:WhiteToGray];
        self.selectedBackgroundView = [[[UIView alloc] initWithFrame:self.frame] autorelease];
        self.selectedBackgroundView.backgroundColor = [[Settings shareSettings]color:GrayToBlack];
        [self sendSubviewToBack:self.selectedBackgroundView];
        self.background.backgroundColor = [[Settings shareSettings]color:WhiteToLightGray];
        
        [self.source removeFromSuperview];
        [self.line removeFromSuperview];
        
        self.ptime = [[UILabel alloc]init];
        self.ptime.textColor = [UIColor lightGrayColor];
        self.ptime.textAlignment = NSTextAlignmentRight;
        self.ptime.font = [UIFont systemFontOfSize:10];
        [self.background addSubview:self.ptime];
        [self.ptime release];
        
        [self notificationHandle];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.background.frame = CGRectMake(12, 12, 350, 95);
    self.img.frame = CGRectMake(15, 10, 85, 70);
    self.title.frame = CGRectMake(110, 10, 225, 45);
    self.ptime.frame = CGRectMake(110, 55, 225, 15);
}

- (void)setMod:(DingyueDetailsModel *)mod{
    if (_mod != mod) {
        [_mod release];
        _mod = [mod retain];
    }
    self.height = 110;
    [self.img sd_setImageWithURL:mod.imgsrc placeholderImage:nil];
    self.title.text = mod.title;
    self.ptime.text = mod.ptime;
}

- (void)notificationHandle{
    [[NSNotificationCenter defaultCenter]addObserverForName:@"changeBackgroundColor" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
        self.backgroundColor = [[Settings shareSettings]color:WhiteToGray];
        self.background.backgroundColor = [[Settings shareSettings]color:WhiteToLightGray];
        self.selectedBackgroundView.backgroundColor = [[Settings shareSettings]color:GrayToBlack];
        self.title.textColor = [[Settings shareSettings]color:BlackToWhite];
    }];
}

- (void)dealloc{
    [_ptime release];
    [super dealloc];
}

@end
